import uuid
from datetime import datetime
from sqlalchemy import (
    Column,
    UUID,
    String,
    DateTime,
    PrimaryKeyConstraint,
    Index,
    text, Integer
)
from src.extension.extension_db import db



class Category(db.Model):
    """类目表模型"""
    __tablename__ = "categorys"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pk_category_id"),
    )

    id = Column(Integer, nullable=False, autoincrement=True)
    name = Column(String(255), nullable=False, server_default=text("''::character varying"))
    updated_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'), server_onupdate=text('CURRENT_TIMESTAMP(0)'))
    created_at = Column(DateTime, nullable=False, server_default=text('CURRENT_TIMESTAMP(0)'))
    @property
    def getExercises(self):
        from src.model import Exercise
        return db.session.query(Exercise).filter(Exercise.category_id == self.id).one_or_none()
